package com.baichang.taoshunda.dao.impl;

import com.baichang.framework.dao.impl.BaseDaoImpl;
import com.baichang.taoshunda.dao.PensionDao;
import com.baichang.taoshunda.entity.Pension;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @param
 * @author: wsl
 * @Date: 2018/11/30 09：15
 * @Description: 养老金
 */
@Repository
public class PensionDaoImpl extends BaseDaoImpl<Pension> implements PensionDao {
    @Override
    public Pension getPensionByUserId(Integer userId) {

        String sql = "SELECT * FROM t_pension WHERE user_id=?  order by id desc LIMIT 1";
        return queryForBean(sql, userId);
    }

    @Override
    public List<Map<String, Object>> findPension(Integer userId, Integer nowPage, Integer pageSize) {
        String sql = "SELECT p.id, p.`name`,g.head_pic as goodsPic, p.type,IFNULL(o.order_type,0) orderType, p.`value`," +
                " p.created , p.user_id, p.order_number, p.money, " +
                "p.monetary, p.pension ,b.store_pic companyPic,b.buss_name companyName, p.pay_type, p.red_packet," +
                " p.address, p.company_id FROM t_pension p LEFT  JOIN t_bussiness b ON b.id=p.company_id " +
                "LEFT JOIN t_order o ON o.order_number =p.order_number " +
                " LEFT  JOIN t_goods g ON p.goods_id =g.id" +
                " WHERE p.user_id = ? ORDER BY p.id DESC";
        return listForMapList(sql, nowPage, pageSize, userId);
    }
}
